package com.qxglxt.qxglxt.model;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import javax.validation.constraints.NotBlank;

import com.fasterxml.jackson.annotation.JsonIgnore;

import org.hibernate.annotations.GenericGenerator;

import lombok.Data;

@Data
@Entity
@Table
@GenericGenerator(name = "jpa-uuid",strategy = "uuid")
public class Roles {

    @Id
    @GeneratedValue(generator = "jpa-uuid")
    @Column(length = 32)
    @NotBlank
    @Column(unique = true,nullable = false)//唯一，非空
    private String name;//角色名称
    private Integer reservation;//预留int
    private String remark;//预留字段
    //用户角色
    @JsonIgnore
    @ManyToMany(cascade = CascadeType.PERSIST,mappedBy = "rolesList",fetch = FetchType.LAZY)
    private List<Users> usersList;
    //角色权限
    @ManyToMany(cascade = CascadeType.REFRESH)
    @JoinTable(name = "role_module",inverseJoinColumns = @JoinColumn(name="module_id")
    ,joinColumns = @JoinColumn(name="role_id") )
    private List<Modules> modulesList;
}